#ifndef UDEFCG_H
#define UDEFCG_H

#include "udef.h"

typedef struct fragarrs {
	ino_t		ino;
	int8_t		fragoff;
	uint32_t	blkindx;
	struct 	fragarrs	*frag;
} FRAGARRS;


typedef struct blockarrs {
	ino_t		ino;
	uint32_t	apindx;
	uint32_t	blkindx; /* index do pole db/ib */
	/* cilova pozice bloku, relativne vzhledem k cg a zacatku dat. bloku */
	uint32_t	blkdest; 
	uint32_t 	flags;
	FRAGARRS	*frag;
} BLOCKARRS;


typedef union diuni {
	struct ufs1_dinode di1;
	struct ufs2_dinode di2;
} DIUNI;


#define		BLCKFREE		0x0001	/* prazdny blok */
#define		BLCKNOMOVE		0x0002	/* nepresunutelny blok */
#define		BLCKLAST		0x0004	/* posledni datovy frag/blok inodu */
#define 	BLCKALONE		0x0008	/* zaplnuje cely blok (vsechny frag.) */


int alloc_blockap(GLBVAL *);
BLOCKARRS* alloc_blockapitem(void);
FRAGARRS* alloc_blockapfrag(void);

void free_blockap(GLBVAL *);
void free_blockapitem(BLOCKARRS *);
void free_blockapfrag(FRAGARRS *);

int alloc_slink(GLBVAL *);
void free_slink(GLBVAL *);

int fill_array(GLBVAL *);
int fill_array_inode(GLBVAL *, ino_t, struct ufs1_dinode *, int *);
uint blktoindx (GLBVAL *, uint32_t);
uint indxtoblk (GLBVAL *, uint32_t);
int fill_array_dbib(GLBVAL *, ino_t, int *, int, int, int, int *, int *);
int fill_array_restblocks(BLOCKARRS **,  struct cg *);

void valid_blocks_order(GLBVAL *);
void print_blockap(GLBVAL *);
void print_bmap(struct cg *, int);
void print_slink(GLBVAL *);
int udefcg(GLBVAL *, int);





#endif
